<?php

namespace App\Http\Controllers\User;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{

    public function getAllDate()
    {
        $date = DB::table('admin_user')->get();
        dd($date);
    }

    
    public function getPicture(Request $request){
        $type = $request->get('type');
        $date = DB::table('picture')->where('type','=',$type)->orderby('id','desc')->get();
        return $date;
    }

    public function getLotteryNum(Request $request){
        $type =  $request->get('type');
        $limit = $request->get('limt') ?  $request->get('limt')  : 20;
        switch($type) {
            case 'hlj11x5':
                $data = $this->dogetLotteryNum('黑龙江11选5',$limit);
                break;
            case 'hljklsf':
                $data = $this->dogetLotteryNum('黑龙江快乐十分',$limit);
                break;
            case 'jlk3':
                $data = $this->dogetLotteryNum('吉林快3',$limit);
                break;
            case 'jlssc':
                $data = $this->dogetLotteryNum('吉林时时彩',$limit);
                break;
            case 'scj7l':
                $data = $this->dogetLotteryNum('四川金7乐',$limit);
                break;
            case 'sckl12':
                $data = $this->dogetLotteryNum('四川快乐12',$limit);
                break;
            default:
                return '参数错误';
        }
        return $data;
    }

    public function dogetLotteryNum($type,$limit){
        $data = DB::table($type)->select('期号','开奖号')->orderby('期号','desc')->limit($limit)->get();
        $data = obj2arr($data);
        $result = array();
        foreach($data as $v){
            $type == '吉林快3'||$type == '吉林时时彩' ? $v['开奖号'] = str_split($v['开奖号']):$v['开奖号'] = explode('-',$v['开奖号']);
            array_push($result,$v);
        }
        return $result;
    }
}
function obj2arr ($obj){
    return json_decode(json_encode($obj),true);
}